package com.gzw.dms.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.ShippingOrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2015/12/29.
 */
public class HomeAdapter extends BaseAdapter{
    private Context mContext;
    private List<ShippingOrderInfo> lsInfo;
    private String state;

    public HomeAdapter(Context _mContext,
                          List<ShippingOrderInfo> _lsInfo,String _state) {
        this.mContext = _mContext;
        this.lsInfo = _lsInfo;
        this.state=_state;

    }


    @Override
    public View getView(int arg0, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub
        // 加载布局文件
        Holder mHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_main, null);
            mHolder = new Holder();
            mHolder.tv_order_goid = (TextView) convertView.findViewById(R.id.ic_shiping_order_goid).findViewById(R.id.tv_name);

            mHolder.tv_shiping_order_num = (TextView) convertView.findViewById(R.id.ic_shiping_order_num).findViewById(R.id.tv_name);
            mHolder.tv_send_time = (TextView) convertView.findViewById(R.id.ic_send_time).findViewById(R.id.tv_name);
            mHolder.tv_end_address = (TextView) convertView.findViewById(R.id.ic_end_address).findViewById(R.id.tv_name);
            mHolder.tv_custom_name = (TextView) convertView.findViewById(R.id.ic_custom_name).findViewById(R.id.tv_name);
            mHolder.tv_edit = (TextView) convertView.findViewById(R.id.tv_edit);
            convertView.setTag(mHolder);
        } else {
            mHolder = (Holder) convertView.getTag();
        }

        ShippingOrderInfo shippingOrderInfo=lsInfo.get(arg0);
        mHolder.tv_shiping_order_num.setText("货运编号:"+shippingOrderInfo.getShiping_order_num());
        mHolder.tv_send_time.setText(" 起运时间:"+shippingOrderInfo.getSend_time());
        mHolder.tv_end_address.setText("终到位置:"+shippingOrderInfo.getEnd_address());
        mHolder.tv_custom_name.setText("发货客户:"+shippingOrderInfo.getCustom_name());
        mHolder.tv_order_goid.setText("出货订单号:"+shippingOrderInfo.getShiping_order_goid());

        if(state.equals("0")){
            mHolder.tv_edit.setText("未接单");
        }else if(state.equals("1")){
            mHolder.tv_edit.setText("已接单");
        }else if(state.equals("2")){
            mHolder.tv_edit.setText("电子围栏签收");
        }else if(state.equals("3")) {
            mHolder.tv_edit.setText("实际签收");
        }
        return convertView;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return lsInfo.get(arg0);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return lsInfo.size();
    }

    static class Holder {
        TextView tv_shiping_order_num;
        TextView tv_send_time;
        TextView tv_end_address;
        TextView tv_custom_name;
        TextView tv_edit;
        TextView tv_order_goid;

    }
}
